package evenements;

import java.awt.Cursor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.omg.CORBA.PRIVATE_MEMBER;

import vues.CasePanel;
import vues.IHM;
import vues.ProfilWindow;
import modele.entites.TypeBot;

public class EcouteurCarte implements MouseListener{

	private IHM ihm;
	private CasePanel caseClique;
	
	public EcouteurCarte(IHM ihm) {
		this.ihm = ihm;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		caseClique = (CasePanel) e.getComponent();
		this.ihm.getPanGrille().setCaseClique(caseClique);
		if (e.getButton() == MouseEvent.BUTTON1) {
			if (this.ihm.getCursor().getName().equals("robot")) {
				ProfilWindow pf = new ProfilWindow(this.ihm, caseClique.getCase().getX(), caseClique.getCase().getY());
				this.ihm.setCursor(Cursor.getDefaultCursor());
				this.ihm.refresh();
			} else if (this.ihm.getCursor().getName().equals("fire")) {
				this.ihm.getHorloge().getSimulateur().addFeu(caseClique.getCase().getX(), caseClique.getCase().getY());
				this.ihm.setCursor(Cursor.getDefaultCursor());
				this.ihm.refresh();
			}
		}
		if (e.getButton() == MouseEvent.BUTTON3) {
			if (((CasePanel) e.getSource()).getImg().getDescription() == null)
				this.ihm.getPanGrille().initPopupMenu(0);
			else if ((((CasePanel) e.getSource()).getImg())
					.getDescription().equals("feu"))
				this.ihm.getPanGrille().initPopupMenu(1);
			else if ((((CasePanel) e.getSource()).getImg())
					.getDescription().equals("robot"))
				this.ihm.getPanGrille().initPopupMenu(2);
			
			this.ihm.getPanGrille().getPopupMenu()
					.show(e.getComponent(), e.getX(), e.getY());
		}
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		
	}

}
